package com.zhangqi.zhxa;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.zhangqi.zhxa.base.impl.ContentFragment;
import com.zhangqi.zhxa.base.impl.LeftMenuFragment;

/**
 * 开发流程：
 * 1.引入SlingMewnu库
 * 2.Activity继承SlidingFragmentActivity
 * 3.onCreate改为public
 * 4.setBehindContentView,设置基本侧边栏效果
 * 5.获取SlidingMenu，深层次定制
 * @author Zhanng Qi
 * @date 2016-4-28
 */
public class MainActivity extends SlidingFragmentActivity {

    private static final String TAG_CONTENT = "TAG_CONTENT";
    private static final String TAG_LEFT = "TAG_LEFT";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //设置侧边栏的布局
        setBehindContentView(R.layout.left_menu);

        //获取侧边栏对象
        SlidingMenu slidingMenu = getSlidingMenu();
        //设置全屏触摸
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        //设置左右侧都可展示，默认是左边
        //slidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
        //设置右边侧边栏
        //slidingMenu.setSecondaryMenu(R.layout.right_menu);
        //修改侧边栏宽度
        slidingMenu.setBehindOffset(200);//屏幕会预留200个像素宽度

        //初始化Fragment
        initFragment();
    }

    /**
     * 初始化Fragment,替换布局
     */
    private void initFragment(){
        FragmentManager fm = getSupportFragmentManager();
        //开启一个事务，fragment比较特殊，需要开启事务
        FragmentTransaction transaction = fm.beginTransaction();
        //将帧布局替换为对应的Fragment,打上标记，为了后面寻找fragment方便
        transaction.replace(R.id.fl_content,new ContentFragment(),TAG_CONTENT);
        transaction.replace(R.id.fl_left_menu,new LeftMenuFragment(),TAG_LEFT);
        transaction.commit();//提交事务

    }
}
